package frist50;

import or.T0445.ListNode;

public class T0002 {

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode node=new ListNode();
        ListNode tmp=node;
        int carry=0;
        while (l1!=null||l2!=null||carry!=0){
            int a=0,b=0,sum;
            if (l1!=null){
                a=l1.val;
                l1=l1.next;
            }
            if(l2!=null){
                b=l2.val;
                l2=l2.next;
            }
            sum=a+b+carry;
            tmp.next=new ListNode(sum%10);
            tmp=tmp.next;
            carry=sum/10;
        }
        return node.next;
    }
}
